package com.hzhr.iot.meterplan.service;

import com.hzhr.iot.collect.sdk.service.Collect_CollectLogService;
import com.hzhr.iot.collect.sdk.service.Collect_CommandService;
import com.hzhr.iot.core.annotation.ApiImplicitInternalParams;
import com.hzhr.iot.core.annotation.CygService;
import com.hzhr.iot.core.constant.AccessModeEnum;
import com.hzhr.iot.core.exception.ServiceException;
import com.hzhr.iot.core.util.HzhrDateUtil;
import com.hzhr.iot.core.util.HzhrTypeUtil;
import com.hzhr.iot.device.sdk.model.collectData.CollectDataGetModel;
import com.hzhr.iot.device.sdk.model.collectData.CollectDataModel;
import com.hzhr.iot.device.sdk.model.collectDevice.CollectDeviceGetModel;
import com.hzhr.iot.device.sdk.model.collectDevice.CollectDeviceModel;
import com.hzhr.iot.device.sdk.model.collectDeviceQuickquery.CollectDeviceQuickqueryItemModel;
import com.hzhr.iot.device.sdk.model.collectDeviceQuickquery.CollectDeviceQuickqueryModel;
import com.hzhr.iot.device.sdk.model.collectDeviceQuickquery.MeterPlan_workOrderItemModel;
import com.hzhr.iot.device.sdk.model.collectDeviceQuickquery.MeterPlan_workOrderlistModel;
import com.hzhr.iot.device.sdk.service.Device_CollectDataService;
import com.hzhr.iot.device.sdk.service.Device_CollectDeviceQuickqueryService;
import com.hzhr.iot.device.sdk.service.Device_CollectDeviceService;
import com.hzhr.iot.login.sdk.model.userCard.UserCardModel;
import com.hzhr.iot.meterplan.constant.Meterplan_ErrorsEnum;
import com.hzhr.iot.meterplan.dao.mapper.generator.custom.ChaobiaogongdanEntityCustomMapper;
import com.hzhr.iot.meterplan.dao.mapper.generator.custom.RuhujihuaEntityCustomMapper;
import com.hzhr.iot.meterplan.entity.RuhujihuaEntity;
import com.hzhr.iot.meterplan.entity.ext.ChaobiaogongdanEntityExt;
import com.hzhr.iot.meterplan.entity.ext.RuhujihuaEntityExt;
import com.hzhr.iot.meterplan.model.meterPlan.MeterPlanGetModel;
import com.hzhr.iot.meterplan.model.meterPlan.MeterPlanModel;
import com.hzhr.iot.meterplan.model.meterPlan_workOrder.MeterPlan_workOrderGetModel;
import com.hzhr.iot.meterplan.model.meterPlan_workOrder.MeterPlan_workOrderModel;
import com.hzhr.iot.meterplan.service.base.BaseService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
@CygService(entity = RuhujihuaEntity.class, model = MeterPlanModel.class)
public class MeterPlan_WorkOrderService extends BaseService {

    @Autowired
    RuhujihuaEntityCustomMapper ruhujihuaEntityCustomMapper;

    @Autowired
    ChaobiaogongdanEntityCustomMapper chaobiaogongdanEntityCustomMapper;

    @Autowired
    Device_CollectDeviceService device_collectDeviceService;  //采集设备

    @Autowired
    Device_CollectDataService collectDataService;  //采集数据

    @Autowired
    Device_CollectDeviceQuickqueryService device_collectDeviceQuickqueryService;

    //region javadoc注释 : get
    /**
     * 查询抄表计划下的状态为“待抄表”抄表工单(无分页) <br/><br/>
     * 1.查询抄表计划，如果抄表计划不存在，抛出异常“抄表计划不存在” <br/>
     * 2.查询该抄表计划下的状态为“待抄表”或“待审核”的抄表工单， <br/>
     *  然后根据抄表工单所对应的采集设备，找到筛选条件所对应的那一天的第一条采集数据或者该设备的最近一条的采集数据进行组合 <br/>
     * 3.返回信息 <br/>
     * @param header <br/>
     * _token : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 令牌;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-code : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户代码;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-user-name : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户名;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-company-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 公司编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-dept-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 部门编号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _hzhr-user-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE');<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易流水号;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-transaction-type : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 交易类型;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : true;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _hzhr-access-mode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 访问模式 0:一般 1:全局;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : 0;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/><br/>
     * @param query <br/>
     * _equal_id : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件：where MeterPlan_workOrderModel.id = id;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : int;<br/>
     * _like_gasUserCode : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件：where MeterPlan_workOrderModel.des like % + #{_like_gasUserCode} + %;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _like_gsaUserName : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件：where MeterPlan_workOrderModel.typeId like % + #{_like_gsaUserName} + %;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _like_gasUserAddress : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件：where MeterPlan_workOrderModel.gasUserAddress  % + #{_like_gasUserAddress} + %;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _like_meterNo : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件：where MeterPlan_workOrderModel.meterNo  % + #{_like_meterNo} + %;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _equal_collectTime : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 筛选条件：where MeterPlan_workOrderModel.collectTime = #{_equal_collectTime};<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _show : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 展示形式 one:展示一个,list:展示列表,null(空值):不展示;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : string;<br/>
     * _show_total : <br/>&nbsp&nbsp&nbsp&nbsp 说明 : 是否展示总数;<br/>&nbsp&nbsp&nbsp&nbsp 是否必填 : false;<br/>&nbsp&nbsp&nbsp&nbsp 默认值 : false;<br/>&nbsp&nbsp&nbsp&nbsp 数据类型 : boolean;<br/><br/>
     * @param meterPlanId 抄表计划id <br/><br/>
     * @throws ServiceException <br/>
     * @see MeterPlan_workOrderGetModel result <br/>
     */ 
    //endregion
    //region 说明 : get
    //查询抄表计划下的状态为“待抄表”抄表工单(无分页)
    //1.查询抄表计划，如果抄表计划不存在，抛出异常“抄表计划不存在”
    //2.查询该抄表计划下的状态为“待抄表”或“待审核”的抄表工单，
    // 然后根据抄表工单所对应的采集设备，找到筛选条件所对应的那一天的第一条采集数据或者该设备的最近一条的采集数据进行组合
    //3.返回信息
    //endregion
    //region 参数 : get
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "meterPlanId", value = "抄表计划id", required = true, dataType = "string", paramType = "path"),
            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_total", value = "是否展示总数", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "equal_id", value = "筛选条件：where MeterPlan_workOrderModel.id = #{equal_id}", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "like_gasUserCode", value = "筛选条件：where MeterPlan_workOrderModel.des like % + #{like_gasUserCode} + %", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "like_gsaUserName", value = "筛选条件：where MeterPlan_workOrderModel.typeId like % + #{like_gsaUserName} + %", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "like_gasUserAddress", value = "筛选条件：where MeterPlan_workOrderModel.gasUserAddress  % + #{like_gasUserAddress} + %", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "like_meterNo", value = "筛选条件：where MeterPlan_workOrderModel.meterNo  % + #{like_meterNo} + %", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "equal_collectTime", value = "筛选条件：where MeterPlan_workOrderModel.collectTime = #{equal_collectTime}", required = false, dataType = "string", paramType = "query"),
    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号", required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号", required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号", required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型", required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局", defaultValue = "0", required = false, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_equal_id", value = "筛选条件：where MeterPlan_workOrderModel.id = id", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_like_gasUserCode", value = "筛选条件：where MeterPlan_workOrderModel.des like % + #{_like_gasUserCode} + %", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_like_gsaUserName", value = "筛选条件：where MeterPlan_workOrderModel.typeId like % + #{_like_gsaUserName} + %", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_like_gasUserAddress", value = "筛选条件：where MeterPlan_workOrderModel.gasUserAddress  % + #{_like_gasUserAddress} + %", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_like_meterNo", value = "筛选条件：where MeterPlan_workOrderModel.meterNo  % + #{_like_meterNo} + %", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_equal_collectTime", value = "筛选条件：where MeterPlan_workOrderModel.collectTime = #{_equal_collectTime}", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_total", value = "是否展示总数", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
    })
    //endregion
    //region 请求 : get
    @RequestMapping(value = "/meter-plans/{meterPlanId}/work-orders", method = RequestMethod.GET)
    //endregion
    public MeterPlan_workOrderGetModel get(Map<String, String> header, String meterPlanId, Map<String, Object> query) throws ServiceException {

       /* 查询抄表计划，如果抄表计划不存在，抛出异常“抄表计划不存在 */
        String id = HzhrTypeUtil.object2string(query.get("_equal_id"));
        String gasUserCodes = HzhrTypeUtil.object2string(query.get("_like_gasUserCode"));
        String gasUserCode = null;
        if (gasUserCodes != null) {
            gasUserCode = "%" + gasUserCodes + "%";
        }

        String gsaUserNames = HzhrTypeUtil.object2string(query.get("_like_gsaUserName"));
        String gsaUserName = null;
        if (gsaUserNames != null) {
            gsaUserName = "%" + gsaUserNames + "%";
        }
        String gasUserAddresss = HzhrTypeUtil.object2string(query.get("_like_gasUserAddress"));
        String gasUserAddress = null;
        if (gasUserAddresss != null) {
            gasUserAddress = "%" + gasUserAddresss + "%";
        }

        String meterNos = HzhrTypeUtil.object2string(query.get("_like_meterNo"));
        String meterNo = null;
        if (meterNos != null) {
            meterNo = "%" + meterNos + "%";
        }

        String collectTime = HzhrTypeUtil.object2string(query.get("_equal_collectTime")); //采集时间 yyyy-MM-dd

        RuhujihuaEntityExt ruhujihuaEntityExt = null;
        ruhujihuaEntityExt = ruhujihuaEntityCustomMapper.selectRuhujihuaAndmeterPlanId(meterPlanId);
        if (ruhujihuaEntityExt == null) {
            throw new ServiceException(Meterplan_ErrorsEnum.METERPLAN_METERGASUSERSERVICE_POST_201);
        }
        String _show = HzhrTypeUtil.object2string(query.get("_show"));
        Boolean _show_total = HzhrTypeUtil.object2boolean(query.get("_show_total"));

        /* 查询该抄表计划下的状态为“待抄表”或“待审核”的抄表工单，
            然后根据抄表工单所对应的采集设备，找到筛选条件所对应的那一天的第一条采集数据或者该设备的最近一条的采集数据进行组合 */
        String rhIds = ruhujihuaEntityExt.getRhId(); //抄表计划下的RhId
        List<ChaobiaogongdanEntityExt> chaobiaogongdanEntityExt = null;
        //抄表工单
        chaobiaogongdanEntityExt = chaobiaogongdanEntityCustomMapper.select2(rhIds, id, gasUserCode, gsaUserName, gasUserAddress, meterNo);
        Integer total = chaobiaogongdanEntityExt.size();
        //2 根据抄表工单所对应的采集设备
        //        -- 用户号 + 表刚号 ==》 燃气表


        /* 返回信息 */
        MeterPlan_workOrderGetModel result = new MeterPlan_workOrderGetModel();
        if ("one".equals(_show)) {
            if (chaobiaogongdanEntityExt.size() != 0) {
                CollectDataModel collectDataModel_1 = null;
                ChaobiaogongdanEntityExt chaobiaogongdanEntityExt1_1 = chaobiaogongdanEntityExt.get(0);
                // 得到对应的采集设备
                Map<String, Object> query1 = new HashMap<>();
                query1.put("_equal_gasUserCode", chaobiaogongdanEntityExt1_1.getCbjlYqzh());
                query1.put("_equal_code", chaobiaogongdanEntityExt1_1.getCbjlGh());
                query1.put("_is_paging", false);
                query1.put("_show_info", true);
                query1.put("_show", "one");
                CollectDeviceGetModel collectDeviceGetModel = device_collectDeviceService.get(initHeader(header), query1);
                if (collectDeviceGetModel.getModel() != null) {
                    //采集设备编号
                    Integer collectDeviceCode = collectDeviceGetModel.getModel().getId();
                    //LAST_COLLECT_TIME 最近采集时间
                    Long lastCollectTime = collectDeviceGetModel.getModel().getLastCollectTime();
                    //筛选采集数据
                    CollectDataGetModel collectDataGetModel_1 = null; //该设备的最近一条的采集数据
                    if (collectDeviceCode != null) {
                        Map<String, Object> query2 = new HashMap<>();
                        query2.put("_equal_collectDeviceId", collectDeviceCode);
                        query2.put("_greaterthanorequal_currentTm", lastCollectTime);  //采集时间 yyyy-MM-dd  大于等于
                        query2.put("_show_info", true);
                        query2.put("_show", "one");
                        collectDataGetModel_1 = collectDataService.get(initHeader(header), query2);
                         collectDataModel_1 = collectDataGetModel_1.getModel(); //采集数据模型(show=one时展示)

                    }

                }
                //采集数据进行拼接组合
                MeterPlan_workOrderModel meterPlan_workOrderModel = new MeterPlan_workOrderModel();
                meterPlan_workOrderModel.setId(chaobiaogongdanEntityExt1_1.getCbjlId());
                meterPlan_workOrderModel.setGasUserCode(chaobiaogongdanEntityExt1_1.getCbjlYqzh());
                meterPlan_workOrderModel.setGasUserName(HzhrTypeUtil.object2string(chaobiaogongdanEntityExt1_1.getCbjlHzMc()));
                meterPlan_workOrderModel.setGasUserAddress(HzhrTypeUtil.object2string(chaobiaogongdanEntityExt1_1.getCbjlYqdzMs()));
                meterPlan_workOrderModel.setMeterNo(chaobiaogongdanEntityExt1_1.getCbjlGh()); //表具钢号
                meterPlan_workOrderModel.setLastReading(chaobiaogongdanEntityExt1_1.getCbjlScbd().toString()); //上次抄表读数
                meterPlan_workOrderModel.setLastAccountReading(chaobiaogongdanEntityExt1_1.getCbjlBcbd().toString()); //上次计费读数
                meterPlan_workOrderModel.setCollectTime(HzhrTypeUtil.long2string(collectDataModel_1.getCurrentTm())); //采集时间(yyyy-MM-dd)
                meterPlan_workOrderModel.setCollectData(HzhrTypeUtil.double2string(collectDataModel_1.getCurrentValue())); //采集数据

                result.setModel(meterPlan_workOrderModel);
            }
        }
        if ("list".equals(_show)) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            System.out.println("开始"+sdf.format(new Date()));
            CollectDeviceQuickqueryModel collectDeviceQuickqueryModel_2 = new CollectDeviceQuickqueryModel();
            MeterPlan_workOrderlistModel meterPlan_workOrderlistModel = new MeterPlan_workOrderlistModel();
            List<MeterPlan_workOrderItemModel> list_2 = new ArrayList<>();
            List<MeterPlan_workOrderModel> meterPlan_workOrderModels = new ArrayList<>();
            for (ChaobiaogongdanEntityExt chaobiaogongdanEntityExt1_2 : chaobiaogongdanEntityExt){
                MeterPlan_workOrderItemModel meterPlan_workOrderItemModel = new MeterPlan_workOrderItemModel();
                meterPlan_workOrderItemModel.setCode(chaobiaogongdanEntityExt1_2.getCbjlGh());
                meterPlan_workOrderItemModel.setGasUserCode(chaobiaogongdanEntityExt1_2.getCbjlYqzh());
                list_2.add(meterPlan_workOrderItemModel);
            }
            meterPlan_workOrderlistModel.setMeterPlanworkOrderList(list_2);
            Map<String, Object> query2 = new HashMap<>();
            query2.put("_equal_collectTime", collectTime);
            collectDeviceQuickqueryModel_2 = device_collectDeviceQuickqueryService.getQuick(initHeader(header, AccessModeEnum.GLOBAL),query2,meterPlan_workOrderlistModel);

            //采集数据进行拼接组合
            for (ChaobiaogongdanEntityExt chaobiaogongdanEntityExt1_3 : chaobiaogongdanEntityExt){
                MeterPlan_workOrderModel meterPlan_workOrderModel = new MeterPlan_workOrderModel();
                meterPlan_workOrderModel.setId(chaobiaogongdanEntityExt1_3.getCbjlId());
                meterPlan_workOrderModel.setGasUserCode(chaobiaogongdanEntityExt1_3.getCbjlYqzh());
                meterPlan_workOrderModel.setGasUserName(HzhrTypeUtil.object2string(chaobiaogongdanEntityExt1_3.getCbjlHzMc()));
                meterPlan_workOrderModel.setGasUserAddress(HzhrTypeUtil.object2string(chaobiaogongdanEntityExt1_3.getCbjlYqdzMs()));
                meterPlan_workOrderModel.setMeterNo(chaobiaogongdanEntityExt1_3.getCbjlGh()); //表具钢号
                meterPlan_workOrderModel.setLastReading(chaobiaogongdanEntityExt1_3.getCbjlScbd().toString()); //上次抄表读数
                meterPlan_workOrderModel.setLastAccountReading(chaobiaogongdanEntityExt1_3.getCbjlBcbd().toString()); //上次计费读数
                //下面是采集数据
                List<CollectDeviceQuickqueryItemModel>  list_3 = collectDeviceQuickqueryModel_2.getList();
                if (list_3 != null) {
                    for (CollectDeviceQuickqueryItemModel collectDeviceQuickqueryItemModel_4 : list_3){
                        if (chaobiaogongdanEntityExt1_3.getCbjlYqzh().equals(collectDeviceQuickqueryItemModel_4.getGasuserCode())&&
                                chaobiaogongdanEntityExt1_3.getCbjlGh().equals(collectDeviceQuickqueryItemModel_4.getCode())){ //如果用户号一致
                            String currentTm = collectDeviceQuickqueryItemModel_4.getCurrentTm();
                            if (!StringUtils.isEmpty(currentTm)) {
                                meterPlan_workOrderModel.setCollectTime(HzhrDateUtil.strToDate(currentTm, "yyyy-MM-dd HH:mm:ss.S").getTime() + "");//时间戳
                            }
                            meterPlan_workOrderModel.setCollectData(collectDeviceQuickqueryItemModel_4.getCurrentValue()); //采集数据
                            break;
                        }
                    }
                }

                if (StringUtils.isEmpty(meterPlan_workOrderModel.getCollectTime())) {
                    if (!StringUtils.isEmpty(collectTime)) {
                        meterPlan_workOrderModel.setCollectTime(HzhrDateUtil.strToDate(collectTime, "yyyy-MM-dd").getTime() + "");
                    }
                }
                meterPlan_workOrderModels.add(meterPlan_workOrderModel);
            }
            result.setModelList(meterPlan_workOrderModels);


        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("结束"+sdf.format(new Date()));
        result.setTotal(total);
        return result;
    }
}






